-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30899: IDLE: Add idle config parser unittest #2662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@mlouielu, thanks for your PR! By analyzing the history of the files in this pull request, we identified @terryjreedy to be a potential reviewer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without looking at the classes, looking good.
Lib/idlelib/idle_test/test_config.py
Outdated
self.assertEqual(parser.GetOptionList('not exist'), []) | ||
|
||
def test_load_file(self): | ||
config_path = support.findfile('cfgparser.1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a file in test dir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, borrow from test_configparser.py
Lib/idlelib/idle_test/test_config.py
Outdated
@@ -3,6 +3,9 @@ | |||
Much is tested by opening config dialog live or in test_configdialog. | |||
Coverage: 27% | |||
''' | |||
import os | |||
import tempfile | |||
from test import support | |||
from test.support import captured_stderr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One style or other, not both. Either add findfile to second or 'support.' to 'captured_stderr' wherever it is. EDIT: fixed.
one = a string | ||
two = true | ||
three = false | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly redundant, but OK as is.
Lib/idlelib/idle_test/test_config.py
Outdated
self.assertEqual(parser.Get('two', 'two'), 'true') | ||
self.assertEqual(parser.Get('two', 'three'), 'false') | ||
self.assertEqual(parser.Get('not', 'exist'), None) | ||
self.assertEqual(parser.Get('not', 'exist', default='DEFAULT'), 'DEFAULT') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be done with a subtest with 5 cases and a subtest with 4 cases and the remaining test. But I think it not worthwhile here. What I have done in situations like this and would like to do here is to name the bound method, "equal = self.assertEqual", and then use that: "equal(parser.Get(...., False)". It is then easier to focus on what is being compared.
EDIT: fixed (eq is fine).
Lib/idlelib/idle_test/test_config.py
Outdated
eq = self.assertEqual | ||
|
||
# Test with type | ||
eq(parser.Get('one', 'one', type='bool'), False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to use assertIs()
. Since False
and True
are singletons, this tests both type and value. Otherwise parser.Get()
returning 0
will pass the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us see whether configparser passes the stricter test.
Lib/idlelib/idle_test/test_config.py
Outdated
eq(parser.Get('two', 'three'), 'false') | ||
|
||
# If option not exist, should return None, or default | ||
eq(parser.Get('not', 'exist'), None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertIsNone()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed here and below.
Lib/idlelib/idle_test/test_config.py
Outdated
|
||
parser.AddSection('Foo') | ||
parser.AddSection('Bar') | ||
self.assertEqual(parser.IsEmpty(), True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertTrue()
.
Or assertIs()
if you want to check that exact bool is returned. But I think this is redundant.
Lib/idlelib/idle_test/test_config.py
Outdated
parser.AddSection('Foo') | ||
parser.AddSection('Bar') | ||
parser.SetOption('Foo', 'bar', 'false') | ||
self.assertEqual(parser.IsEmpty(), False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertFalse()
.
Lib/idlelib/idle_test/test_config.py
Outdated
|
||
# Set option to not exist section should create section and return True | ||
self.assertEqual(parser.SetOption('Bar', 'bar', 'true'), True) | ||
self.assertEqual(sorted(parser.sections()), ['Bar', 'Foo']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use assertCountEqual()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a looser test, but I read the doc, as it is new to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using assertCountEqual()
is OK, ConfigParser
were using assertEqual
to test, we only need to care about the item is correct or not here.
Lib/idlelib/idle_test/test_config.py
Outdated
parser.AddSection('Foo') | ||
parser.SetOption('Foo', 'bar', 'true') | ||
|
||
self.assertEqual(parser.RemoveOption('Foo', 'bar'), True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertTrue()
/assertFalse()
Serhiy, thanks for the review. I still have to remember to use the specific tests. I think the code reads better. |
Louie, I think this is ready to merge and plan to do so tomorrow. Review changes if you can. I re-ordered the functions in one of the classes and corresponding test class so the order makes sense and is the same in both. So the actual change is less drastic than it might look at first. If I had thought about it, I might have done the re-order in a separate commit. I added a few test to complete coverage. |
@terryjreedy I take a brief look and seems good. I'll take the deep review today. |
@terryjreedy Fix some comment and the |
Lib/idlelib/idle_test/test_config.py
Outdated
@@ -26,6 +30,161 @@ def tearDownModule(): | |||
idleConf.userCfg = usercfg | |||
|
|||
|
|||
class IdleConfParserTest(unittest.TestCase): | |||
"""Test ththat IdleConfParser works""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Louie, you need to follow the same comment rule you have reminded Cheryl of. |
…arser subclasses. (pythonGH-2662) Patch by Louie Lu. (cherry picked from commit 50c9435)
Thanks @terryjreedy @csabella @serhiy-storchaka for reviewing this, learn a lot. |
No description provided.